Apache DeltaSpike - the CDI toolbox

Antoine Sabot-Durand

  • Senior Software Engineer
  • CDI co-spec lead, Java EE 8 EG
  • Red Hat, Inc.
  • @antoine_sd
  • www.next-presso.com
  • github.com/antoinesd

Rafael Benevides

  • Senior Software Engineer
  • DeltaSpike P.M.C member
  • Red Hat, Inc.
  • @rafabene
  • github.com/rafabene

Agenda

  • CDI Portable Extensions
  • What is DeltaSpike ?
  • Core Module
  • Other DeltaSpike Modules
  • Question & Answers

CDI Portable Extensions

Portable extensions

OCP (Open Closed Principle) in CDI
OCP final

Extensions, what for?

To integrate 3rd party libraries, frameworks or legacy components
To change existing configuration or behavior
To extend CDI and Java EE
Thanks to them, Java EE can evolve between major releases

Extensions, how?

rubik
Implement javax.enterprise.inject.spi.Extension
Register the Extension
Observe SPI events at boot time related to the bean manager lifecycle

More concretely

Service provider of the service javax.enterprise.inject.spi.Extension declared in META-INF/services
Just put the fully qualified name of your extension class in this file
import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.Extension;

public class CdiExtension implements Extension {

    void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd) {
    }
    //...

    void afterDeploymentValidation(@Observes AfterDeploymentValidation adv) {
    }
}

Example: Injecting a String from a Properties file

    @Inject @Property("key1")
    private String property1;

    @Inject @Property("key2")
    private String property2;
It can be achieved by @Produces but it could lead to: Unsatisfied dependencies for type String with qualifiers @Property…​
    @Produces
    @Property("key1")
    public String propriedade1Producer()
    {
        return propertiesFile.getProperty("key1");
    }

Solution: Create a CDI Portable Extension

powerful
One of the most powerful feature of the CDI specification
Not really popularized, partly due to:
  1. Their high level of abstraction
  2. The good knowledge on Basic CDI and SPI
  3. Lack of information (CDI is often reduced to a basic DI solution)

What is DeltaSpike ?

CDI & DeltaSpike

hook
CDI is a specification. It doesn’t provide business features
but it includes a powerful hook to add these business features
The "Poortable extensions" feature is this hook
Thanks to it, CDI can be easily enhanced with new high level features

Apache DeltaSpike is…​

toolbox
A collection of ready to use extensions to help you in your projects
A toolbox to help you develop new CDI portable extensions
A great way to learn how to develop your own extension by browsing the source code
The most obvious entry point to CDI eco-system

Where does it come from ?

TODO Move content to here

A bit of history

TODO Move content to here

Modules and dependencies

TODO Move content to here